package tiled.mapeditor.util;

import java.awt.Component;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JList;
import javax.swing.DefaultListCellRenderer;

public class ImageCellRenderer extends DefaultListCellRenderer
{
    public ImageCellRenderer()
    {
        setOpaque(true);
    }

    public Component getListCellRendererComponent(JList list, Object value,
            int index, boolean isSelected, boolean cellHasFocus)
    {
        super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

        Image img = (Image)value;
        if (img != null)
        {
            setIcon(new ImageIcon(img));
        }
        else
        {
            setIcon(null);
        }
        setText(null);

        return this;
    }
}
